<?php
	include_once '../modelo/images_model.php';
	
	class ControladorImagenes {
		
		public $insertString = "INSERT INTO IMAGES (IMAGE_FILE_NAME) VALUES ";
		public $selectString = "SELECT * FROM IMAGES WHERE IMAGE_FILE_NAME = ";
		public $query = "";
		public $imageModel = null;
		
		function __construct(){
			$this->imageModel = new ImagesModel();
		}
		
		function searchImageId($img_file_name){
			
			$query = $this->selectString."'".$img_file_name."'";			 						
			$select = $this->imageModel->searchImageId($query);
			
				while ($row = $select)
				  return $row[0];
		}			
		
		function searchImageName($app_id){

			$query = "SELECT IMAGE_FILE_NAME FROM IMAGES WHERE IMAGE_ID = (SELECT IMAGE_ID FROM
			APPLICATIONS WHERE APP_ID = ".$app_id.")";
			
			$select = $this->imageModel->searchImageId($query);
			
				while ($row = $select)
				  return $row[0];
		}
		
		
		function createImage($img_file_name){
			$query = $this->insertString ."('".$img_file_name."')";
			return $this->imageModel->createImage($query);			
		}
	}

?>